1. Field of the Invention
The present invention relates to computer programming. More specifically, the present invention relates to a method and an apparatus for characterizing artificiality in object code. The object code may have been produced by transforming a source language into object code via a compiler.
2. Related Art
Computer programs are typically written in source code and then compiled into object code for execution on a specific platform or by a specific virtual machine. During the transformation from source code to object code, some constructs from the source code are preserved in the resultant object code, while other constructs may not be preserved. Furthermore, the resultant object code typically incorporates constructs that were not present in the original source code, such as implementation details specifying how the compiler implements the semantics of the programming language.
In many instances, programmers find themselves in the situation where they have a collection of object code, and they want to ask questions about the object code in terms of source code semantics. In these instances, programmers often use reflective tools to analyze the object code to create corresponding source code, or to answer their questions about the object code in terms of source code semantics, if the source code is unavailable. Various techniques have been developed to help the programmer distinguish between constructs in the object code that correspond to constructs in the source code and constructs in the object code that associated with a specific compiler implementation.
For example, the ClassFile format used by the JAVA Virtual Machine is able to flag classes, fields, and methods as “synthetic.” (Note that the terms JAVA, JVM and JAVA VIRTUAL MACHINE are trademarks of SUN Microsystems, Inc. of Santa Clara, Calif.) The synthetic flag indicates that the class/field/method was generated implicitly by a compiler and does not appear in source code. This flag is typically used to mark ClassFile content that is an implementation detail of how the compiler implements the semantics of a programming language such as JAVA. As such, in most cases, a synthetic artifact should not be relied on by JAVA Virtual Machine implementations, nor exposed by Application Programming Interfaces (APIs,) nor manipulated by tools. Please note that in some instances, certain synthetic artifacts can be relied upon to be created in a particular way.
Separately, the semantics of a programming language sometimes mandate that artifacts be automatically provided if not written explicitly by the programmer. For example, in the JAVA programming language, a class has a default no-args constructor if the programmer does not supply any constructor, and an enum type has certain methods which are part of the type's public API but which cannot (for safety reasons) by written by a programmer. It is useful for a number of reasons to mark such artifacts in the ClassFile as implicitly generated. However, this cannot be accomplished with the “synthetic” flag because the artifacts are not implementation details and should not be hidden in reflective APIs presenting a source-level view.